﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System.Collections.Generic;
using System.Windows;
using System.Windows.Data;
using System.Windows.Controls;
using FinPlusAssembler;
using FinPlusInterfaces;

namespace FinPlusCompView
{
    public class FinPlusGridColSelectBox : FinPlusGridColBase
    {
        [State(Test = true)]
        public override bool IsValid { get; set; }

        //construct
        public FinPlusGridColSelectBox(string name, string links, CheckBox filterCheck, bool isEnabled = false)
        {
            var selectList = new List<string>();
            if(string.IsNullOrEmpty(links))
                selectList.AddRange(Structure.ToList(name));
            else
                foreach (var link in links.Split(','))
                    selectList.AddRange(Structure.ToList(link));

            var tb = new FrameworkElementFactory(typeof(FinPlusValueSelectBox));
            tb.SetBinding(FinPlusValueSelectBox.IdProperty, new Binding(BeanField.Id.ToString()) { Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
            tb.SetBinding(FinPlusValueSelectBox.ValueProperty, new Binding(BeanField.Type.ToString()) { Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
            tb.SetBinding(FinPlusValueSelectBox.TextProperty, new Binding(name) { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
            tb.SetValue(FinPlusValueSelectBox.IsEnabledProperty, isEnabled);
            tb.SetValue(FinPlusValueSelectBox.ItemSourceProperty, selectList);
            var et = new DataTemplate() { VisualTree = tb };

            var dt = TextBlockCell(name);

            Header = HeaderFilterCheck(name, filterCheck,"SCreate");
            ClipboardContentBinding = new Binding(name) { Mode = BindingMode.OneWay };
            CellEditingTemplate = et;
            CellTemplate = dt; 
            SortMemberPath = name; 
            CanUserSort = true;
        }
    }
}
